﻿using NewBusiness.Domain.Uow.Data;
using NewBusiness.Domain.Uow.Repositories;
using NewBusiness.Domain.Uow;
using NewBusiness.Domain.Uow.Data;
using NewBusiness.Domain.Uow.Repositories;

namespace NewBusiness.Domain.Uow
{
    public interface IUow
    {
        //IRepository<Data.UserBookmark> UserBookmarks { get; }
        IRepository<Data.Url> Urls { get; }
        IRepository<Data.Bookmark> Bookmarks { get; }
        IRepository<Data.Tag> Tags { get; }
        IRepository<Data.UserProfile> Users { get; }
        IRepository<Data.UserReport> UserReports { get; }
        IRepository<Data.UserUrlSettings> UserUrlSettings { get; }


        void Commit();
    }

    public class Uow : IUow
    {
        protected readonly DataContext Data;

        public Uow(DataContext data,  IRepository<Data.UserBookmark> userBookmarks, IRepository<Data.Url> urls, IRepository<Data.Bookmark> bookmarks,
            IRepository<Data.Tag> tags, IRepository<Data.UserProfile> userProfiles, IRepository<Data.UserReport> userReports,
            IRepository<Data.UserUrlSettings> userUrlSettings)
        {
            Data = data;
            UserBookmarks = userBookmarks;
            Urls = urls;
            Bookmarks = bookmarks;
            Tags = tags;
            Users = userProfiles;
            UserReports = userReports;
            UserUrlSettings = userUrlSettings;
        }
        public IRepository<Data.UserBookmark> UserBookmarks { get; private set; }
        public IRepository<Data.Url> Urls { get; private set; }
        public IRepository<Data.Bookmark> Bookmarks { get; private set; }
        public IRepository<Data.Tag> Tags { get; private set; }
        public IRepository<Data.UserProfile> Users { get; private set; }
        public IRepository<Data.UserReport> UserReports { get; private set; }
        public IRepository<Data.UserUrlSettings> UserUrlSettings { get; private set; }
        public virtual void Commit()
        {
            Data.SaveChanges();
        }        
    }
}
